////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_PLATFORM_SURFACE_XWINDOWS_H__
#define __WN_PLATFORM_SURFACE_XWINDOWS_H__

#include "WNPlatform/inc/WNSurface.h"
#include "WNContainers/inc/WNResourcePointer.h"
#include "WNConcurrency/inc/WNCountMutex.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <GL/glx.h>

namespace WNConcurrency {
    class WNThread;
}
namespace WNPlatform {
    class WNSurfaceManagerXWindows;
    class WNSurfaceXWindows : public WNSurface {
    public:
        virtual WNNativeGraphicsHandle GetNativeGraphicsHandle();
        
        virtual WNSurfaceError Resize(WN_UINT32 _width, WN_UINT32 _height);
        virtual WNSurfaceError Move(WN_UINT32 _x, WN_UINT32 _y);
        virtual WN_BOOL IsFullscreen();
        virtual WNSurfaceError SetFullscreen(WN_BOOL _fs);

        virtual WN_UINT32 GetWidth() const;
        virtual WN_UINT32 GetHeight() const;
        virtual WN_UINT32 GetX() const;
        virtual WN_UINT32 GetY() const;
        WNSurfaceXWindows(WNPlatform::WNSurfaceManagerXWindows& _surfaceManager);
        WN_BOOL Initialize(WN_UINT32 _x, WN_UINT32 _y, WN_UINT32 _width, WN_UINT32 _height, Display* _display, XVisualInfo * _visualInfo);
        virtual ~WNSurfaceXWindows();
    private:
        static WN_VOID SurfaceThread(WNSurfaceXWindows* _surface);
        Atom mDeleteMessage;
        WN_BOOL mExiting;
        WNPlatform::WNSurfaceManagerXWindows& mManager;
        WNConcurrency::WNCountMutex mThreadCreationMutex;
        Display* mDisplay;
        Window mWindow;
        WNConcurrency::WNThread* mWindowThread;
        WN_BOOL mFullscreen;
        WN_UINT32 mX;
        WN_UINT32 mY;
        WN_UINT32 mWidth;
        WN_UINT32 mHeight;
    };
}

#endif // __WN_PLATFORM_SURFACE_XWINDOWS_H__